package org.sen.db;

import java.util.List;

import javax.sql.DataSource;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.sen.utils.PublicUtils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DBCPDataSource {
	private static ComboPooledDataSource ds = null;

	public DBCPDataSource() {
	}

	public static DataSource getDataSource() {
		if (ds == null) {
			try {
//				Properties prop = new Properties();
//				prop.load(DBCPDataSource.class.getClassLoader().getResourceAsStream("db.properties"));
				ds = new ComboPooledDataSource("c3p0-config.xml");
//				Connection conn = ds.getConnection();
//				ds = BasicDataSourceFactory.createDataSource(prop);
			} catch (Exception e) {
				// TODO 自动生成的 catch 块
				System.out.println("dbcp数据源初始化异常");
				// e.printStackTrace();
			}
		}
		return ds;
	}

	public static void main(String[] args) {
		String strSql = "select * from USERCOMMENT";
		List<org.sen.bean.ComentBean> lst = PublicUtils.getInstance(DBProvider.class).query(strSql,
				new BeanListHandler<org.sen.bean.ComentBean>(org.sen.bean.ComentBean.class));
		if (lst != null && lst.size() > 0) {
			for (org.sen.bean.ComentBean comentBean : lst) {
				System.out.println(comentBean.toString());
			}
		}
	}

}